package iso3.pt.action;

import iso3.pt.model.Asignatura;
import iso3.pt.model.Profesor;
import iso3.pt.service.PtDaoService;
import iso3.pt.service.PtService;

import java.util.Map;
import java.util.Set;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class StudentSubjectMarkingAction  extends ActionSupport 
{

	private static final long serialVersionUID = 1L;
	
	private String concepto = null;
    private String nota = null;

	private Integer dniAlumno;	
	private int idAsig; 
	
	private Profesor profesor = null;
	private Set<Asignatura> lecturerSubjects = null;
	
	public String execute() throws Exception 
	{
		PtService service = new PtDaoService();
		
		@SuppressWarnings("rawtypes")
		Map session = ActionContext.getContext().getSession();
		setProfesor((Profesor) session.get("profesor"));
		setLecturerSubjects((Set<Asignatura>) service.getAsignaturasProfesor(profesor.getId()));
		
		if (getNota().equals("") || getConcepto().equals("")) 
		{
			addActionError(getText("errors.invalid.mark.specify"));
			return INPUT;
		}
		else
		{
			try
			{
				service.addEvaluacion(getConcepto(), Float.valueOf(getNota()), getIdAsig(), getDniAlumno());
				
				return SUCCESS;
			} 
			catch (NumberFormatException e)
			{
				addActionError(getText("errors.invalid.mark"));
				
				return ERROR;
			}
		}
	}
	
    public String getConcepto()
	{
		return concepto;
	}

	public void setConcepto(String concepto)
	{
		this.concepto = concepto;
	}

	public String getNota()
	{
		return nota;
	}

	public void setNota(String nota)
	{
		this.nota = nota;
	}
	
	public Integer getDniAlumno()
	{
		return dniAlumno;
	}

	public void setDniAlumno(Integer dniAlumno)
	{
		this.dniAlumno = dniAlumno;
	}

	public int getIdAsig()
	{
		return idAsig;
	}

	public void setIdAsig(int idAsig)
	{
		this.idAsig = idAsig;
	}

	public Profesor getProfesor()
	{
		return profesor;
	}

	public void setProfesor(Profesor profesor)
	{
		this.profesor = profesor;
	}

	public Set<Asignatura> getLecturerSubjects()
	{
		return lecturerSubjects;
	}

	public void setLecturerSubjects(Set<Asignatura> lecturerSubjects)
	{
		this.lecturerSubjects = lecturerSubjects;
	}

}
